class Solution {
public:
    int missingNumber(vector<int>& nums) {
        int n = nums.size();
        nums.push_back(1);
        int flag = 0;
        for(int i = 0;i < n;i++){
            int index = abs(nums[i]);
            nums[index] = -abs(nums[index]);
            if(nums[i] == 0){
                flag = i;
            }
        }
        for(int i = 0;i <= n;i++){
            if(nums[i] > 0){
                return i;
            }
        }
        return flag;
    }
};
